<?php
/* @var $this GaleriController */
/* @var $model Galeri */
/* @var $form CActiveForm */
$request = Yii::app()->request;
if ($request->enableCsrfValidation) {
    echo CHtml::metaTag($request->getCsrfToken(), 'csrf-token');
    echo CHtml::metaTag($request->csrfTokenName, 'csrf-param');
}
?>

<div class="form">
    <?php $form = $this->beginWidget('CActiveForm', array(
    'id' => 'galeri-form',
    'enableAjaxValidation' => false,)); ?>
    <?php $idImage = sha1(uniqid() . Now('yyyyMMddhhmmss'));
    echo CHtml::hiddenField('image_name_tmp', $idImage);?>
    <p class="note">Fields with <span class="required">*</span> are required.</p>

    <div>&nbsp;</div>
    <?php echo $form->errorSummary($model); ?>

    <table border="0" cellpadding="0" cellspacing="0" id="id-form">
        <tr>
            <th valign="top">File Gambar *</th>
            <td class="idform">
                <div id="cropImg"><?php echo $model->isNewRecord ? "" :
                    "<img id='image' src='" . bu() . '/img/galeri/full/' . $model->id . '.jpg' .
                        "' style=\"width: 159px; height: 106px; margin-left: 0px; margin-bottom: 10px;\">"; ?></div>
                <?php
                $this->widget('ext.EAjaxUpload.EAjaxUpload', array(
                        'id' => 'uploadFile',
                        'postParams' => array('tmp' => $idImage),
                        'config' => array(
                            'action' => $this->createUrl('/backend/galeri/upload'),
                            'allowedExtensions' => array("jpg", "jpeg", "gif", "png"),
                            //array("jpg","jpeg","gif","exe","mov" and etc...
                            'sizeLimit' => 500 * 1024,
                            // maximum file size in bytes       //$('#cropDialog').dialog('open');
                            'minSizeLimit' => 10,
                            //*1024*1024,// minimum file size in bytes $('.qq-upload-button').css('display', 'none');
                            'onComplete' => "js:function(id, fileName, responseJSON){
                                        $('#uploadFile').hide();
                                        if (responseJSON.success) {
                                                $('#cropImg').load('" . $this->createUrl('/backend/galeri/cropImg') . "/'+responseJSON.filename);
                                                $('#Users_image').val(responseJSON.filename);
                                                $('#Users_imageExt').val((responseJSON.filename.substring(responseJSON.filename.lastIndexOf('.'))).toLowerCase());
                                                $('#uploadFile').show();
                                        } else {
                                                $('#uploadFile').html('<p  width=\"160\">' + responseJSON.error +'</p>');
                                        }
                                }",
                            'messages' => array(
                                'typeError' => "{file} has invalid extension. Only {extensions} are allowed.",
                                'sizeError' => "{file} is too large, maximum file size is {sizeLimit}.",
                                'minSizeError' => "{file} is too small, minimum file size is {minSizeLimit}.",
                                'emptyError' => "{file} is empty, please select files again without it.",
                                'onLeave' => "The files are being uploaded, if you leave now the upload will be cancelled."),
                            'showMessage' => "js:function(message){ alert(message); }")));
                ?>
                <span style="color: red;">max upload 0.5 MB</span>
            </td>
            <td class="idform">
            </td>
        </tr>
         <tr>
            <th valign="top"><?php echo $model->getAttributeLabel('parent_id'); ?></th>
            <td class="idform">
                <?php echo $form->dropDownList($model, 'parent_id', $list_parent, array(
            'empty' => '(Pilih Kategori)',
            'style' => 'width:200px',
            'class' => 'styledselect_form_1')); ?>
            </td>
            <td class="idform">
                <?php if ($model->hasErrors('parent_id')) echo "<div class='error-left'></div>"; ?>
                <?php echo $form->error($model, 'parent_id', array('class' => 'error-inner')); ?>
            </td>
        </tr>
        <tr>
            <th valign="top"><?php echo $model->getAttributeLabel('nama') . '*'; ?></th>
            <td class="idform">
                <?php echo $form->textField($model, 'nama',
                array('size' => 60, 'maxlength' => 250, 'class' => 'inp-formpanjang')); ?>
            </td>
            <td class="idform">
                <?php if ($model->hasErrors('nama')) echo "<div class='error-left'></div>"; ?>
                <?php echo $form->error($model, 'nama', array('class' => 'error-inner')); ?>
            </td>
        </tr>
        <tr>
            <th valign="top"><?php echo $model->getAttributeLabel('name_'); ?></th>
            <td class="idform">
                <?php echo $form->textField($model, 'name_',
                array('size' => 60, 'maxlength' => 250, 'class' => 'inp-formpanjang')); ?>
            </td>
            <td class="idform">
                <?php if ($model->hasErrors('name_')) echo "<div class='error-left'></div>"; ?>
                <?php echo $form->error($model, 'name_', array('class' => 'error-inner')); ?>
            </td>
        </tr>
        <tr>
            <th valign="top"><?php echo $model->getAttributeLabel('isi') . '*'; ?></th>
            <td class="idform">
                <?php $this->widget('ext.tinymce.TinyMce', array(
                    'model' => $model,
                    'attribute' => 'isi',
                    'fileManager' => array(
                        'class' => 'ext.elFinder.TinyMceElFinder',
                        'connectorRoute' => 'elfinder/connector',),
                    'htmlOptions' => array('rows' => 6, 'cols' => 60,),)); ?>
            </td>
            <td class="idform">
                <?php if ($model->hasErrors('isi')) echo "<div class='error-left'></div>"; ?>
                <?php echo $form->error($model, 'isi', array('class' => 'error-inner')); ?>
            </td>
        </tr>
        <tr>
            <th valign="top"><?php echo $model->getAttributeLabel('content'); ?></th>
            <td class="idform">
                <?php $this->widget('ext.tinymce.TinyMce', array(
                    'model' => $model,
                    'attribute' => 'content',
                    'fileManager' => array(
                        'class' => 'ext.elFinder.TinyMceElFinder',
                        'connectorRoute' => 'elfinder/connector',),
                    'htmlOptions' => array('rows' => 6, 'cols' => 60,),)); ?>
            </td>
            <td class="idform">
                <?php if ($model->hasErrors('content')) echo "<div class='error-left'></div>"; ?>
                <?php echo $form->error($model, 'content', array('class' => 'error-inner')); ?>
            </td>
        </tr>
    </table>
    <div class="row">
        <?php
        $this->beginWidget('zii.widgets.jui.CJuiDialog', array(
                'id' => 'cropDialog',
                'options' => array(
                    'title' => 'Crop Image',
                    'modal' => true,
                    'width' => 728,
                    'height' => 600,
                    'autoOpen' => false,)));

        echo '<div id="cropImg"></div>';

        $this->endWidget('zii.widgets.jui.CJuiDialog');
        ?>
    </div>
    <div class="row buttons">
        <?php echo CHtml::submitButton($model->isNewRecord ? 'Create' : 'Save', array('class' => 'form-submit')); ?>
    </div>

    <?php $this->endWidget(); ?>
</div><!-- form -->